﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Nim2D.Managers;

namespace Nim2D.Components {

	public struct Appearance : Component {

		public Texture2D Texture;
		public Color Color;

		public Appearance(Texture2D texture, Color color) {
			Texture = texture;
			Color = color;
		}

		public void Update(ref Entity entity, GameTime gameTime) {

			//=====( Begin gathering data )==========

			// Position data.
			Dictionary<int, Component> allPositions = ComponentManager.ComponentDictionaries[ComponentManager.ComponentType.Position];
			Position position = (Position)allPositions[entity.Components[ComponentManager.ComponentType.Position]];
			Vector2 pos = position.Pos;

			// Appearance data.
			Dictionary<int, Component> allAppearances = ComponentManager.ComponentDictionaries[ComponentManager.ComponentType.Appearance];
			Appearance thisEntityAppearance = (Appearance) allAppearances[entity.Index];
			Texture2D texture = thisEntityAppearance.Texture;
			Color color = thisEntityAppearance.Color;

			//=====( End gathering data )============

			// Do this component's work.
			Engine.SpriteBatch.Draw(texture, pos, color);
		}

	}

}